<script setup>
import { ref, onMounted } from 'vue';
import { checkIpRestriction } from './utils/api';
import WelcomeModal, { shouldShowWelcomeModal } from './components/WelcomeModal.vue';

// 不再直接引入ChatTerminal组件，由路由系统管理

const isIpRestricted = ref(false);
const showWelcomeModal = ref(false);

// 关闭弹窗
const closeWelcomeModal = () => {
  showWelcomeModal.value = false;
};

onMounted(async () => {
  const { restricted } = await checkIpRestriction();
  isIpRestricted.value = restricted;
  
  // 检查是否需要显示欢迎弹窗
  if (shouldShowWelcomeModal()) {
    showWelcomeModal.value = true;
  }
});
</script>

<template>
  <div class="app-container">
    <header class="app-header">
      <div class="header-flex">
        <div class="logo-container">
          <img src="./assets/logo.svg" class="logo vue" alt="Logo" />
          <h1 style="font-size: 1.2rem;">AI Tool</h1>
        </div>
        <nav class="nav-bar">
          <router-link to="/ai/chat" class="nav-link" active-class="active-link" exact>AI 聊天</router-link>
          <router-link v-if="!isIpRestricted" to="/ai/chat/all" class="nav-link" active-class="active-link">测试数据</router-link>
          <router-link to="/table-structure" class="nav-link" active-class="active-link">表结构</router-link>
          <router-link to="/business-terms" class="nav-link" active-class="active-link">辅助信息</router-link>
        </nav>
      </div>
    </header>
    <main>
      <router-view />
    </main>
    
    <!-- 欢迎弹窗组件 -->
    <WelcomeModal :show="showWelcomeModal" @close="closeWelcomeModal" />
  </div>
</template>

<style scoped>

.app-container {
  display: flex;
  flex-direction: column;
  height: 98%;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.app-header {
  padding: 0.5rem 1rem;
  background-color: #ffffff;
  width: 100%;
  box-sizing: border-box;
}
.header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  height: 2em;
  will-change: filter;
  transition: filter 300ms;
}

.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}

.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}

main {
  flex: 1;
  padding: 0;
  display: flex;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: auto;
}

.nav-bar {
  display: flex;
  gap: 1rem;
  margin-left: 2rem;
}

.nav-link {
  color: #333;
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 1.2rem;
  border-radius: 8px;
  transition: all 0.3s ease;
  border: 2px solid transparent;
  background: transparent;
}

.nav-link:hover {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
  border-color: #f97316;
}

.active-link {
  background: linear-gradient(135deg, #646cff, #747bff);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(100, 108, 255, 0.2);
}

.active-link:hover {
  background: linear-gradient(135deg, #5b65f0, #6b73ff);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(100, 108, 255, 0.4);
  border-color: #5b65f0;
}
</style>
